package com.aaa.controller;


import com.aaa.Tool.TXT_file_tools;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;


@Controller
@RequestMapping(value = "/delete")
public class Delete {

//    @Autowired
//    private SQL_Mapper sql_mapper;


    @GetMapping("/{file_name}")
    @ResponseBody
    public String edit(Model model, @PathVariable String file_name) {
        TXT_file_tools txt_file_tools = new TXT_file_tools();
        String txt_folder_path = txt_file_tools.get_txt_folder_path();
        System.out.println(txt_folder_path);

        String full_path = txt_folder_path + File.separator + file_name;
        System.out.println(full_path);

        // java 删除文件, 删除成功返回 true, 删除失败返回 false
        File file = new File(full_path);
        boolean b = file.delete();   // 尝试删除文件并返回删除结果
        if (b){
            return "success";
        }else {
            return "fail";
        }
    }

}



